package com.ess.project.examine.record.compute;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description: 体型
 * 体型未达到上述标准者，可进一步采用体脂百分比评定
 * @Date: Created in 7:45 下午 2021/3/7
 * @Author: daihui
 * @Modified By:
 */
public class BodilyFormExamineStrategy implements BaseExamine<Float> {

    private static final Map<Integer, Float[]> MAN_DIC_DATA = new HashMap<>(6);
    private static final Map<Integer, Float[]> WOMAN_DIC_DATA = new HashMap<>(6);
    public static final int PARAM_SIZE = 3;


    static {
        initDicData();
    }

    /**
     * 数组第1、2个元素为BMI下限和BMI上限
     * 数组第3、4个元素为体脂下限和体脂上限
     */
    private static void initDicData(){
        Float[] manGradeArray24 = {18.5F, 25.9F, 6.0F, 20.7F};
        Float[] manGradeArray2529 = {18.5F, 26.9F, 6.0F, 21.7F};
        Float[] manGradeArray3039 = {18.5F, 27.9F, 6.0F, 22.7F};
        Float[] manGradeArray4049 = {18.5F, 28.9F, 6.0F, 23.7F};
        Float[] manGradeArray5059 = {18.5F, 29.4F, 6.0F, 24.3F};
        Float[] manGradeArray60 = {18.5F, 29.9F, 6.0F, 24.9F};
        MAN_DIC_DATA.put(DATA_KEY_24, manGradeArray24);
        MAN_DIC_DATA.put(DATA_KEY_2529, manGradeArray2529);
        MAN_DIC_DATA.put(DATA_KEY_3039, manGradeArray3039);
        MAN_DIC_DATA.put(DATA_KEY_4049, manGradeArray4049);
        MAN_DIC_DATA.put(DATA_KEY_5059, manGradeArray5059);
        MAN_DIC_DATA.put(DATA_KEY_60, manGradeArray60);

        Float[] womanGradeArray24 = {18.5F, 23.9F, 14.0F, 30.1F};
        Float[] womanGradeArray2529 = {18.5F, 24.9F, 14.0F, 30.6F};
        Float[] womanGradeArray3039 = {18.5F, 25.9F, 14.0F, 31.1F};
        Float[] womanGradeArray4049 = {18.5F, 26.9F, 14.0F, 31.6F};
        Float[] womanGradeArray5059 = {18.5F, 27.4F, 14.0F, 31.7F};
        Float[] womanGradeArray60 = {18.5F, 27.9F, 14.0F, 31.9F};
        WOMAN_DIC_DATA.put(DATA_KEY_24, womanGradeArray24);
        WOMAN_DIC_DATA.put(DATA_KEY_2529, womanGradeArray2529);
        WOMAN_DIC_DATA.put(DATA_KEY_3039, womanGradeArray3039);
        WOMAN_DIC_DATA.put(DATA_KEY_4049, womanGradeArray4049);
        WOMAN_DIC_DATA.put(DATA_KEY_5059, womanGradeArray5059);
        WOMAN_DIC_DATA.put(DATA_KEY_60, womanGradeArray60);
    }

    @Override
    public String compute(Object args, String gender, Float... grade) {
        Integer age = (Integer) args;
        if (grade.length == PARAM_SIZE) {
            float height = grade[0];
            float weight = grade[1];
            float badyFat = null == grade[2] ? 0 : grade[2];
            Float[] arr;
            if (MAN.equals(gender)) {
                arr = MAN_DIC_DATA.get(BaseExamine.bodyFatDicKey(age));
            } else {
                arr = WOMAN_DIC_DATA.get(BaseExamine.bodyFatDicKey(age));
            }
            return BaseExamine.qualified(height, weight, badyFat, arr);
        } else {
            return "参数异常";
        }

    }


}
